﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.ESS.APP.App_UI.Commons;
using KPIS.GERP.ESS.BLL;
using Telerik.Web.UI;
using _WebShared.Classes;

namespace KPIS.GERP.ESS.APP.App_UI.UserControls
{
    public partial class AC_ApproveRequest : System.Web.UI.UserControl
    {
        B_MessageSend send = new B_MessageSend();
        ActivityRequestBLL ActReqBLL = new ActivityRequestBLL();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void LoadRequestDtls(string SendSeq)
        {
            DataSet ListDataCommand = ActReqBLL.GetMsgSend(SendSeq);
            if (ListDataCommand.Tables.Count > 0)
            {
                DataTable table = ListDataCommand.Tables[0];
                if (table.Rows.Count > 0)
                {
                    lbSubject.Text = table.Rows[0]["send_text"].ToString();
                    lbRefSeq.Text = table.Rows[0]["ref_seq"].ToString();;
                    lbToEmp.Text = table.Rows[0]["to_emp_seq"].ToString();
                    //lbStart.Text = string.Format("{0:dd/MM/yyyy}", table.Rows[0]["send_date"]);
                    //lbEnd.Text = string.Format("{0:dd/MM/yyyy}", table.Rows[0]["send_date"]);
                    //lbLocation.Text=table.Rows[0]["Name"].ToString();
                    //lbCity.Text=table.Rows[0]["Name"].ToString();
                    //lblTextAmount.Text = table.Rows[0]["Name"].ToString();                    
                    LoadActivityRequest(lbRefSeq.Text, lbToEmp.Text);
                }
            }
        }
        public void LoadActivityRequest(string RefSeq, string ToEmp)
        {
           string strEmpSeq = Session["EmpSeq"].ToString();

           RadGrid1.DataSource = send.GetFull(strEmpSeq, null,"0", null, null, null);
           RadGrid1.DataBind(); 
            
        }
        protected void btnApprove_OnClick(object sender, EventArgs e)
        {
            for (int i = 0; i < RadGrid1.Items.Count; i++)
            {
                GridDataItem item = RadGrid1.Items[i]; 
                if (RadGrid1.Items[i].Selected)
                {
                    //ActReqBLL.InsertActRequest(item["ref_seq"].Text, item["from_emp_seq"].Text, "0", "", Session["EmpSeq"].ToString());
                    ActReqBLL.UpdateSendStatus(item["send_seq"].Text,"1", Session["EmpSeq"].ToString());
                }
            }
            LoadActivityRequest(lbRefSeq.Text, lbToEmp.Text);
        }
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                string strApprove = item["approve"].Text;

                item["ClientSelectColumn"].Enabled = strApprove != "1";
            }
        }
        protected void btnDisApprove_OnClick(object sender, EventArgs e)
        {
            for (int i = 0; i < RadGrid1.Items.Count; i++)
            {
                GridDataItem item = RadGrid1.Items[i];
                if (RadGrid1.Items[i].Selected)
                {
                    //ActReqBLL.InsertActRequest(item["act_request_seq"].Text, item["act_request_seq"].Text, "1", "", Session["EmpSeq"].ToString());
                }
            }
           
        }
    }
}